<template>
	<div class="selectDep">
		<el-dialog title="请选择实验室" :visible.sync="dialogVisible" width="55%" :close-on-click-modal='false' :show-close="false" :close-on-press-escape="false"
		 :modal-append-to-body='false' v-loading="loading"
    element-loading-text="实验室数据初始化中..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.6)">
			<el-table :data="labData" size="mini" ref="standardTable" height="280" @cell-click="clickcell">
				<el-table-column property="name" label="实验室名称" fixed min-width="60px">
				</el-table-column>
				<el-table-column property="groupName" label="组织" fixed min-width="60px">
				</el-table-column>
			</el-table>
		</el-dialog>
	</div>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		name: "cas",
		data() {
			return {
				dialogVisible: false,
				labData:[],
				haveLab: false,
				labNull: false,
				errdescription: '',
        loading:false,
			}
		},
		props: [ 'addVisible'],

		mounted() {
      localStorage.removeItem('isFrom')
      sessionStorage.setItem('loginAccount',this.getUrlField('token'));
			this.getlabAuth();
			this.getDictionaryData();
		},
		methods: {
      getUrlField(name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
      },


			getlabAuth(){
				this.$http({
					 apiUrl: 'login/getlabAuth.htm',
				     method: 'post',
				}).then(res=>{
					if(res.code == 0){
							this.labData = res.data;
									if (res.data.length == 1) {
										this.clickcell(res.data[0])
									} else {
										this.labData = res.data;
										this.dialogVisible = true
									}

					}else if(res.code == 11202){
            let CasAddress = localStorage.getItem('CasAddress')
            if(CasAddress && CasAddress!=''){
              window.location.href = CasAddress;
            }else{
              this.$router.push('/')
            }
					}

				})
			},
			clickcell(val) {
        this.loading = true;
				this.$http({
					apiUrl: 'login/chooselab.htm',
					method: 'post',
					params: { id: val.id, mark:val.mark},
					isJson: false
				}).then(res => {
          this.loading = false;
					if (res.code === 0) {
						sessionStorage.setItem("defaultlabData", JSON.stringify(val));
						this.$router.push('/shuisi')
						this.$store.commit('changenowpage', 'homePage');
						this.$store.state.menuName = '';
						this.$store.state.pageName = '';
						this.$store.dispatch('dogetDictionary')

					}

				})
			},
			// 登陆成功存储数据字典数据
			getDictionaryData() {
				this.$http({
					method: 'post',
					apiUrl: '/system/readDictionary.htm',
				}).then(res => {
					if (res.code == 0) {
						sessionStorage.setItem('dataDictionaryList', JSON.stringify(res.data));

					}
				}).catch((err) => {

				});
			},

		},
		computed: {
			...mapState(['pageName', 'menuName']),
		},
	}

</script>

<style>
	.selectDep {}

	.selectDep .el-dialog__header {
		padding: 10px;
		text-align: center;
	}

	.selectDep .el-dialog__header .el-dialog__title {
		font-size: 16px;
	}

	.selectDep .el-dialog__body {
		padding: 20px 10px;
	}

	.selectDep .el-table th,
	.el-table td {
		text-align: center !important;
	}
	.selectDep  .el-dialog__wrapper{
		background: #ccc;
	}

	.selectDep .labNull .el-dialog__header {
		padding: 0 !important;
	}

	.selectDep .labNull .el-dialog__footer {
		text-align: center !important;
	}
</style>
